<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:variable name="lotid" select="0"/>
 
<xsl:template match="/">

   <xsl:element name="UserPref">
     <xsl:attribute name="name">lotid</xsl:attribute>
     <xsl:attribute name="display_name">Lottery</xsl:attribute>
     <xsl:attribute name="datatype">enum</xsl:attribute>
     <xsl:attribute name="required">true</xsl:attribute>

     <xsl:for-each select="lotteries/lottery">

       <xsl:sort select="@locale" data-type="text" order="ascending"/>
       <xsl:sort select="@name" data-type="text" order="ascending"/>

       <xsl:element name="EnumValue">
         <xsl:attribute name="value">
           <xsl:value-of select="position() - 1"/>
         </xsl:attribute>
         <xsl:attribute name="display_value">
           <xsl:value-of select="@locale"/> - <xsl:value-of select="@name"/>
         </xsl:attribute>
       </xsl:element>

     </xsl:for-each>

   </xsl:element>

 </xsl:template>

</xsl:stylesheet>
